﻿using System;
using System.Runtime.Serialization;
using MugenMvvmToolkit.Interfaces;
using MugenMvvmToolkit.Utils;

namespace MugenMvvmToolkit.Models
{
    /// <summary>
    ///     Represents the entity state entry.
    /// </summary>
#if WPF
    [Serializable]
#endif
    [DataContract(IsReference = true)]
    public class EntityStateEntry : IEntityStateEntry
    {
        #region Constructors

        /// <summary>
        ///     Initializes a new instance of the <see cref="EntityStateEntry" /> class.
        /// </summary>
        public EntityStateEntry(EntityState state, object entity)
        {
            Should.NotBeNull(entity, "entity");
            State = state;
            Entity = entity;
        }

        #endregion

        #region Methods

        /// <summary>
        ///     Creates new instance of <see cref="IEntityStateEntry{T}" />.
        /// </summary>
        public static IEntityStateEntry<T> Create<T>(EntityState entityState, T entity)
        {
            return new EntityStateEntry<T>(entityState, entity);
        }

        #endregion

        #region Implementation of IEntityStateEntry

        /// <summary>
        ///     Gets or sets the state of the <see cref="EntityState" />.
        /// </summary>
        public EntityState State { get; private set; }

        /// <summary>
        ///     Gets the entity object.
        /// </summary>
        public object Entity { get; private set; }

        #endregion
    }

    /// <summary>
    ///     Represents the entity state entry.
    /// </summary>
#if WPF
    [Serializable]
#endif
    [DataContract(IsReference = true)]
    public sealed class EntityStateEntry<T> : EntityStateEntry, IEntityStateEntry<T>
    {
        #region Constructors

        /// <summary>
        ///     Initializes a new instance of the <see cref="EntityStateEntry{T}" /> class.
        /// </summary>
        public EntityStateEntry(EntityState state, T entity)
            : base(state, entity)
        {
        }

        #endregion

        #region Implementation of IEntityStateEntry

        /// <summary>
        ///     Gets the entity object.
        /// </summary>
        public new T Entity
        {
            get { return (T)base.Entity; }
        }

        #endregion
    }
}